import 'package:dio/dio.dart';

typedef MapProvider = Map<String, dynamic> Function();
typedef FutureMapProvider = Future<Map<String, dynamic>> Function();

class RequestInterceptor extends Interceptor {
  RequestInterceptor({this.headersProvider});

  /// 填充 headers。
  final MapProvider? headersProvider;

  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    final headers = headersProvider?.call();
    if (headers != null && headers.isNotEmpty) {
      options.headers.addAll(headers);
    }
    return handler.next(options);
  }
}